package com.ies.dx.dex.file;

import com.ies.dx.util.Hex;
import com.ies.dx.util.Input;

public class field_id_item extends dex_item
{
    private int class_idx; //ushort
    private int type_idx; //ushort
    private int name_idx; //uint
    
    private String classname = null;
    private String typename = null;
    private String name = null;
    
 
    public field_id_item(dex_file file)
    {
        super(file);
    }

    public void read(Input dis)
    {
        try
        {
            class_idx = dis.readUnsignedShort();
            type_idx = dis.readUnsignedShort();
            name_idx = dis.readInt();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public void show()
    {
//        System.out.println("[class_idx]         :" + class_idx + " (0x" + Hex.u4(class_idx) + ")");
//        System.out.println("[type_idx]          :" + type_idx + " (0x" + Hex.u4(type_idx) + ")");
//        System.out.println("[name_idx]          :" + name_idx + " (0x" + Hex.u4(name_idx) + ")");
        System.out.println(getData());
    }
    
    public String getClassName()
    {
        if (classname == null)
            classname = mFile.getType(class_idx);
        return classname;
    }
    
    public String getTypeName()
    {
        if (typename == null)
            typename = mFile.getType(type_idx);
        return typename;
    }
    
    public String getName()
    {
        if (name == null)
            name = mFile.getString(name_idx);
        return name;
    }

    public String getData() 
    {
        return getTypeName() + " " + getName() + "(" + getClassName() + ")";
    }

    @Override
    public void readData(Input dis)
    {
        // TODO Auto-generated method stub
        
    }
}
